package com.lej.core.utils

import android.app.ActivityManager
import android.content.Context
import android.os.Process

/**是否是主进程*/
var isMainProcess: Boolean? = null

fun Context.isMainProcess(): Boolean {
    isMainProcess?.let { return it }
    val am = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
    val processInfoList = am.runningAppProcesses ?: return false
    val mainProcessName = applicationInfo.processName
    val myPid: Int = Process.myPid()
    for (info in processInfoList) {
        if (info.pid == myPid && mainProcessName == info.processName) {
            return true
        }
    }
    return false
}